<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>厂商账户列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<script type="text/javascript">
	var grid = null;
	var _mfrId = '${mfrId}';
    var _modelTypCd = '045';
    var isCheckVerify = '${isCheckVerify}';
    var isDetail = '${isDetail}';
    var isFlow = '${isFlow}';
    var isMdfPayTyp = '${isMdfPayTyp}';
    var isModify = '${isModify}';

	$(function () {
		var _url = '<%=path%>/mfr/mfrbankacc/initList.do?mfrId=' + _mfrId ;
	    $("#ligergrid1").ligerGrid({
	    	url: _url,
	    	method : 'get',
	        columns: [
	            { display: '收款方', align:'left',name:'rcptUnt', width: 120 },
	            { display: '收款账号',align:'left', name: 'accNo', width: 120,
	            	render: function (rowdata, rowindex, value){
	            		var h='<a href="javascript:showDetail(';
	            		h+="'"+rowdata.id+"'";
	                    h+=')">'+rowdata.accNo+'</a>';
	                	return h;
	            	}
	            },
	            { display: '开户行',align:'left', name: 'bkNm', width: 120 },
	            { display: '开户行行号',align:'left', name: 'bkNo', width: 120 },
	            { display: '区域',align:'left', name: 'rgnNms', width: 120 ,
	            	render: function (rowdata, rowindex, value){
	            		var h= '<span class="gridTip" title="' + value +'">'+ value +'</span>'
	            		     return h;
	            		}
				},
	            { display: '账号类型', name: 'bizTypCdNm', width: 80},
	            { display: '账号用途', name: 'purpCdNm', width: 200},
	            { display: '评审状态', name: 'audStsCdNm', width: 80 },
	            { display: '流程编号', width: 180,
	            	render: function (rowdata, rowindex, value){
	            		var h= "";
	            		if(StringUtils.isNotEmpty(rowdata.pno)){
	            			if(rowdata.pno.indexOf("账号")>-1){
			            		h='<a href="javascript:showFlow(';
	            			}else{
			            		h='<a href="javascript:showMfrFlow(';
	            			}
		            		h+="'"+rowdata.pinstId+"'";
		            		h+=",'"+rowdata.audStsCd+"'";
		            		h+=",'"+rowdata.id+"'";
		                    h+=')">'+rowdata.pno+'</a>';
	            		}
	                	return h;
	            	}	
	            },
	            { display: '提报人', name: 'crtUsrNm', width: 100 },
	            getOperateColumn()
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        rownumbers:true,
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	    $("#clearBtn").click(function(event) {
	        $("#resetBtn").click();  //重置 input-text
	        var form = liger.get("searchBar");
	        form.setData({  //重置select等特殊表单
	            "brCd": " ",
	            "audStsCd": " "
	        });
	    });
	});
	//显示流程
    function showFlow(_pInstId,_audStsCd,_businessKey){
    	if(StringUtils.isEmpty(_pInstId)){
    		UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
    		return;
    	}
    	var _formUrl = "/mfr/mfrbankacc/toDetailPage.do?isFlow=1@@isDetail=1@@id=";
    	var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
    	Add_navTab('tab_mfr_bank_flow_'+_pInstId,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
    function showMfrFlow(_pInstId,_audStsCd,_businessKey){
    	if(StringUtils.isEmpty(_pInstId)){
			UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
			return;
		}
		var _formUrl = "/mfr/mfrBscInfo/toDetailPage.do?isFlow=1@@isDetail=1@@id=";
		var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
		Add_navTab('tab_mfr_flow_'+_pInstId,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
	
	function getOperateColumn(){
		return { 
        	display: '操作',width:250,align:'left',
        	render: function (rowdata, rowindex, value){
                var h = '';
        	    if(!isFlow || isFlow == '1'){
                    h='<a class="sq-button-hasicon" href="javascript:startFlow(';
                    h+="'"+rowdata.id+"'";
                    h+=')"><i class="sqBtnIco_6"></i>发起审核流程</a>';
                }
                var g = '';
                if(!isModify || isModify == '1'){
                    g='<a class="sq-button-hasicon" href="javascript:change(';
                    g+="'"+rowdata.id+"'";
                    g+=')"><i class="sqBtnIco_4"></i>修改</a>';
                }

                var u = '' ;
                if(!isModify || isModify == '1'){
                    u='<a class="sq-button-hasicon" href="javascript:changePurpCd(';
                    u+="'"+rowdata.id+"'";
                    u+=')"><i class="sqBtnIco_4"></i>修改账户用途</a>';
                }

                var d = '';
                if(!isModify || isModify == '1'){
                    d='<a class="sq-button-hasicon" href="javascript:deleteRecord(';
                    d+="'"+rowdata.id+"'";
                    d+=')"><i class="sqBtnIco_7"></i>删除</a>';
                }
	            //如果账号流程实例ID和供应商流程实例ID相同  则允许修改
	            /*if(StringUtils.isNotEmpty(rowdata.pinstId) && StringUtils.isNotEmpty(proIntId) && rowdata.pinstId==proIntId){
	            	return g;
	            }*/
	            //审核中 审核通过 不能再次发起流程 木有修改和删除
	            if(rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_IN || rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_PASS
	            		|| rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_RETURN_BACK){
	            	return u;
	            }
	            return h+g+d;
        	}
		};
	}
	
	var callback = function () {
		grid.reload();
    };
	//新增数据
	function add(){
        $.ligerDialog.SQopen({
            width: 900,
            height:400,
            title : '新增厂商账户',
            url:'<%=path%>/mfr/mfrbankacc/toAddPage.do?mfrId='+_mfrId,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	 //修改数据
	function change(_id){
		 if(!_id)return;
		$.ligerDialog.SQopen({
            width: 900,
            height:400,
            title : '修改厂商账户信息',
            url:'<%=path%>/mfr/mfrbankacc/toAddPage.do?id='+_id+'&mfrId='+_mfrId,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	function changePurpCd(_id){
		 if(!_id)return;
		$.ligerDialog.SQopen({
            width: 900,
            height:400,
            title : '修改厂商账户信息',
            url:'<%=path%>/mfr/mfrbankacc/toAddPage.do?disable=1&id='+_id+'&mfrId='+_mfrId,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	//详情
	function showDetail(_id){
		if(!_id)return;
		$.ligerDialog.SQopen({
            width: 900,
            height:400,
            title : '厂商账号详情',
            url:'<%=path%>/mfr/mfrbankacc/toDetailPage.do?id='+_id,
            buttons: [{
	                text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	//删除数据
	function deleteRecord(_id){
		if(!_id)return;
		var _ids = [];
		_ids.push(_id);
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/mfr/mfrbankacc/removeByIds.do',
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
	}
	//发起审核流程
	function startFlow(_id){
		if(!_id)return;
		//发起流程确认  2017-6-8 by HEWANGZE
        var modelTyp = FlowConstant.FLOW_MODEL_TYP_MFR_BANK;//流程业务分类-厂商账号
        if(!modelTyp){
            modelTyp = _modelTypCd ;
        }
        if(StringUtils.isEmpty(modelTyp)){
            console.log("modelTyp is null");
            return;
        }
        $.ligerDialog.confirm(FlowConstant.FLOW_ADD_START_CONFIRM, function (flag) {
			if(flag == false)return;
	        var flowDialog = $.ligerDialog.SQopen({
	            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
	            width: 700,
	            height:400,
	            title : '请选择要发起的流程',
	            buttons: [{
		                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
		                onclick: function (item, Dialog) {
		                    if (Dialog.onOk) Dialog.onOk();
		                }
		            }, {
		                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
		                onclick: function (item, Dialog) {
		                    if (Dialog.onCancel) Dialog.onCancel();
		                }
		            }
		        ],
	            onClose: function () {
	            	var json = flowDialog._DATA;
	            	console.log(json);
	            	if(!json){
	                	return;
	            	}
	            	var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
	        		$.ajax({
	            		type: 'post',
	            		dataType:'json',
	            		data:{
	            			id:_id,
	            			procDefKey:json.procDefKey,
	            			procDefId:json.procDefId,
	            			procNo:json.procNo,
                            modelTyp:modelTyp
	            		},
	            		//url: '<%=path%>/product/splBank/addFlowStart.do',
                        url: '<%=path%>/commonBankAcc/flow/startAccessFlow.do',
                        success:function(msg){
	            			wait_dialog.close();
	            			 if(msg.success == 1){
	          					 UIUtils.alertSuccessHold1(msg.info);
	           				 	 grid.reload();
		           			 }else{
		          				UIUtils.alertErrorHold1(msg.info);
		           			 }
	            		}
	            	});
	            }
	        });
        });
	}
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	
</script>

<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="clearFix"></div>
            <div class="btnsBox formBtns notRight">
            	<c:if test="${empty isFlow || isFlow != '1' }">
	                <span id="addBtn" class="sq-button-round" onclick="add();">新增</span>
            	</c:if>
            </div>
        </div>
    </form>
</div>
</div>
<div id="ligergrid1" class="sq-grid"></div>


</body>
</html>